/* FULL BACKGROUND */

$(function() {
    fullBg();
});

navHeight = ($(window).width() > 640) ? 74 : 60;

$(window).on('resize', function() {
    fullBg();
    navHeight = ($(window).width() > 640) ? 74 : 60;
});

function fullBg() {
    var background = $('.full-img');
    var h = $(window).height();
    var centered = $('.center-content');
    var ch = centered.height();
    if (h > ch + 60) {
        background.height(h);
        centered.css({
            'top': '50%',
            'margin-top': -ch/2
        });
    } else {
        background.height(ch + 60);
        centered.css({
            'top': '60px',
            'margin-top': 0
        });
    }
}

$('.toggle-alert').click(function(e){
    e.preventDefault();
    $('.alert-warning').toggleClass('active');
    setTimeout(function(){
        fullBg();
    }, 300);
});

$('.alert-warning .close').click(function(e){
    e.preventDefault();
    $('.alert-warning').toggleClass('active');
    setTimeout(function(){
        fullBg();
    }, 300);
});

/* SHADOWBOX */

Shadowbox.init({
    handleOversize: "drag"
});

$('.carousel').carousel({
    interval: 6000
});
$(window).scroll(function() {
    if ($(window).scrollTop() > 15) {
        $('.navbar').addClass('nav-scroll');
    } else {
        $('.navbar').removeClass('nav-scroll');
    }
});

/* SCROLLTO NAV */

function scrollToElement(selector, time, verticalOffset) {
    time = typeof(time) != 'undefined' ? time : 700;
    verticalOffset = typeof(verticalOffset) != 'undefined' ? verticalOffset : 0;
    element = $(selector);
    offset = element.offset();
    offsetTop = offset.top + verticalOffset - navHeight;
    $('html, body').animate({
        scrollTop: offsetTop
    }, time);
}

$('.scrollTo').on('click', function(e) {
    e.preventDefault();
    var n = $(this).attr('href');
    if ($(window).width() < 768) {
        $('.navbar-toggle').trigger('click');
    }
    console.log(navHeight);
    scrollToElement(n);
});
$('.navbar-brand').on('click', function(e) {
    e.preventDefault();
    $('html, body').animate({
        scrollTop: 0
    }, 700);
});

/* GET STARTED IN NAV */

$(window).on('scroll', function() {
    if ($(window).scrollTop() > 150) {
        if ($('#navStarted').css('opacity') == '0') {
            $('#navStarted').animate({width: '110px', opacity: '1'}, 400);
        }
    } else {
        if ($('#navStarted').css('opacity') == '1') {
            $('#navStarted').animate({width: '0px', opacity: '0'}, 400);
        }
    }
});